package com.xrit.sunnyday.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xrit.sunnyday.dao.MemberDao;
import com.xrit.sunnyday.dao.OrderDao;
import com.xrit.sunnyday.service.ReportService;
import com.xrit.sunnyday.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;


    @Override
    public Map<String, Object> findBusinessReportData() throws Exception {
        //今天
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周一
        String thisWeekDay = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本周日
        String lastWeekDay=DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());
        //获取本月
        String firstDay4ThisMonth=DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //获取本月月底
        String lastDayOfThisMonth=DateUtils.parseDate2String(DateUtils.getLastDayOfThisMonth());

        /*==========会员统计==================*/
        //今日新增会员数
        Integer todayNewMember=memberDao.findMemberCountByDate(today);
        //总会员数
        Integer totalMember=memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember=memberDao.findMemberCountAfterDate(thisWeekDay);
        //本月新增会员数
        Integer thisMonthNewMember=memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        /*==========预约统计==================*/
        //今日预约数
        Integer todayOrderNumber=orderDao.findOrderCountByDate(today);
        //今日到诊数
        Integer todayVisitsNumber=orderDao.findVisitsCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber=orderDao.findOrderCountWeekDate(thisWeekDay,lastWeekDay);
        //本周到诊数
        Integer thisWeekVisitsNumber=orderDao.findVisitsCountAfterDate(thisWeekDay);
        //本月预约数
        Integer thisMonthOrderNumber=orderDao.findOrderCountMonthDate(firstDay4ThisMonth,lastDayOfThisMonth);
        //本月到诊数
        Integer thisMonthVisitsNumber=orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

        /*==========热门套餐统计==================*/

        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        Map<String, Object> map = new HashMap<>();
        map.put("reportDate",today);
        //今日新增会员数
        map.put("todayNewMember",todayNewMember);
        //总会员数
        map.put("totalMember",totalMember);
        //本周新增会员数
        map.put("thisWeekNewMember",thisWeekNewMember);
        //本月新增会员数
        map.put("thisMonthNewMember",thisMonthNewMember);
        //今日预约数
        map.put("todayOrderNumber",todayOrderNumber);
        //今日到诊数
        map.put("todayVisitsNumber",todayVisitsNumber);
        //本周预约数
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        //本周到诊数
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        //本月预约数
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        //本月到诊数
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        //热门套餐
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }


}
